package com.frogs.ucenter.v1.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.frogs.framework.base.web.BaseController3;
import com.frogs.system.web.api.response.FailResponse;
import com.frogs.system.web.api.response.Response;
import com.frogs.system.web.exception.AppBaseException;
import com.frogs.system.web.exception.ServiceOperationException;
import com.frogs.ucenter.v1.request.QEAddRequest;
import com.frogs.ucenter.v1.request.UserAccountInfoAddRequest;
import com.frogs.ucenter.v1.request.UserBaseInfoMergeRequest;
import com.frogs.ucenter.v1.request.UserBindEmailRequest;
import com.frogs.ucenter.v1.request.UserBindPhoneRequest;
import com.frogs.ucenter.v1.request.UserShippingAddressAddRequest;
import com.frogs.ucenter.v1.request.UserShippingAddressUpdateRequest;
import com.frogs.ucenter.v1.request.WechatUserInfoUpdateRequest;
import com.frogs.ucenter.v1.request.WechatUserPhoneBindRequest;
import com.frogs.ucenter.v1.service.QuestionExamineService;
import com.frogs.ucenter.v1.service.UserAccountInfoService;
import com.frogs.ucenter.v1.service.UserBaseInfoService;
import com.frogs.ucenter.v1.service.UserShippingAddressService;
import com.frogs.ucenter.v1.util.ApiConstants;

@Controller(ApiConstants.VERSION + "questionExamineController")
@RequestMapping("/" + ApiConstants.VERSION)
public class QuestionExamineController extends BaseController3 {

	private static final String ROOT = "/questionExamine";

	private static final String QE_ADD = ROOT + "/add";

	private static final String SHIP_ADRESS_ADD = ROOT + "/addShipAddr";

	@Resource(name = ApiConstants.VERSION + "questionExamineService")
	private QuestionExamineService questionExamineService;
	@Resource(name = ApiConstants.VERSION + "userBaseInfoService")
	private UserBaseInfoService userBaseInfoService;
	@Resource(name = ApiConstants.VERSION + "userAccountInfoService")
	private UserAccountInfoService userAccountInfoService;

	@Resource(name = ApiConstants.VERSION + "userShippingAddressService")
	private UserShippingAddressService userShippingAddressService;

	/**
	 * 新增问卷调查入库
	 * 
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(QE_ADD)
	public Response qeAdd(HttpServletRequest request, ModelMap model) {
		Response response = null;
		try {

			QEAddRequest req = new QEAddRequest();
			UserBaseInfoMergeRequest reqname = new UserBaseInfoMergeRequest();
			UserBindEmailRequest userBindEmailReq = new UserBindEmailRequest();
			UserBindPhoneRequest userBindPhoneReq = new UserBindPhoneRequest();
			UserAccountInfoAddRequest accountInfoAddReq = new UserAccountInfoAddRequest();

			req.parse(request);
			reqname.parse(request);
			userBindEmailReq.parse(request);
			userBindPhoneReq.parse(request);
			accountInfoAddReq.parse(request);

			response = questionExamineService.addQuestionExamine(req);
			response = userBaseInfoService.mergeUserBean(reqname);

			response = userAccountInfoService.bindEmail(userBindEmailReq);
			response = userAccountInfoService.bindPhone(userBindPhoneReq);

		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}

	@RequestMapping(SHIP_ADRESS_ADD)
	public Response shipAddrAdd(HttpServletRequest request, ModelMap model) {
		Response response = null;
		try {
			UserShippingAddressAddRequest addReq=new UserShippingAddressAddRequest();
			addReq.parse(request);
					
			userShippingAddressService.insert(addReq);

			
		} catch (Exception e) {
			response = new FailResponse();
			if (e instanceof AppBaseException) {
				response.setTip(e.getMessage());
			} else {
				response.setTip("errro message" + e.getMessage());
			}
		}
		return response;
	}

}
